package web.css;

import java.util.Arrays;
import java.util.List;

import org.apache.wicket.AttributeModifier;
import org.apache.wicket.Component;
import org.apache.wicket.ajax.AjaxRequestTarget;
import org.apache.wicket.ajax.form.AjaxFormComponentUpdatingBehavior;
import org.apache.wicket.markup.html.WebComponent;
import org.apache.wicket.markup.html.WebPage;
import org.apache.wicket.markup.html.form.DropDownChoice;
import org.apache.wicket.markup.html.form.Form;
import org.apache.wicket.model.IModel;
import org.apache.wicket.model.PropertyModel;

public class CssHome extends WebPage{
	private static final long serialVersionUID = 1L;
	private String cssSeleccionado;
	private List<String> css; 

	public CssHome() {
		cssSeleccionado = "tranquil.css";
		css = Arrays.asList("tranquil.css", "normal.css");
		
		Form<Void> form = new Form<Void>("form"); 
		add(
			css(),
			form.add(cambiarCss())
		);
	}

	
	private Component css() {
		PropertyModel<String> modelo = new PropertyModel<String>(this, "cssSeleccionado");
		WebComponent css = new WebComponent("css");
		css.add(new AttributeModifier("href", modelo));
		return css;
	}
	
	private Component cambiarCss() {
		List<String> source = this.css;
		IModel<String> modelo = new PropertyModel<String>(this, "cssSeleccionado");
		DropDownChoice<String> choice = new DropDownChoice<String>("css_select", modelo, source);
		choice.add(new AjaxFormComponentUpdatingBehavior("onchange"){
			private static final long serialVersionUID = 1L;

			@Override
			protected void onUpdate(AjaxRequestTarget target) {
				setResponsePage(getPage());
			}
		});
		return choice;
	}


	//getters&setters
	public String getCssSeleccionado() {
		return cssSeleccionado;
	}

	public void setCssSeleccionado(String cssSeleccionado) {
		this.cssSeleccionado = cssSeleccionado;
	}

	public List<String> getCss() {
		return css;
	}

	public void setCss(List<String> css) {
		this.css = css;
	}
}